package com.lc202310;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 *
 * @Create 2023/10/19 23:15
 * @Version 1.0
 */
public class Solution1726 {
    public int tupleSameProduct(int[] nums) {
        //将两数乘积转为key，存入map,而 n=1,res=0;n=2,res=8;n=3,res=24;
        int length = nums.length;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < length - 1; i++) {
            for (int j = i + 1; j < length; j++) {
                int key = nums[i] * nums[j];
                map.put(key, map.getOrDefault(key, 0) + 1);
            }
        }
        int res = 0;
        for (int n : map.values()) {
            res += n * (n - 1) * 4;
        }
        return res;
    }
}
